package com.huawei.hwid.api.common;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.cloudservice.CloudRequestHandler;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.helper.handler.ErrorStatus;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;

class d extends SafeBroadcastReceiver {
    private Context a;
    private CloudRequestHandler b;
    private boolean c = false;

    public d(Context context, CloudRequestHandler cloudRequestHandler) {
        this.a = context;
        this.b = cloudRequestHandler;
    }

    public void onReceiveMsg(Context context, Intent intent) {
        if (!this.c) {
            Bundle bundle = new Bundle();
            bundle.putBoolean("BindSafePhoneBroadcastReceiver", true);
            e.a(this.a, bundle);
            this.c = true;
            e.a(context);
            if (intent != null) {
                try {
                    CharSequence action = intent.getAction();
                    e.b("BindSafePhoneBroadcastReceiver", "BindSafePhoneBroadcastReceiver receiver : ", true);
                    if (TextUtils.isEmpty(action) || !"com.huawei.hwid.ACTION.BINDSAFEPHONE.SUCCESS".equals(action)) {
                        e.b("BindSafePhoneBroadcastReceiver", "BindSafePhoneBroadcastReceiver receiver not ACTION_BIND_SAFEPHONE", true);
                    } else if (intent.hasExtra(HiAnalyticsConstant.BI_KEY_RESUST)) {
                        String stringExtra = intent.getStringExtra(HiAnalyticsConstant.BI_KEY_RESUST);
                        Bundle bundle2 = new Bundle();
                        if ("1".equals(stringExtra)) {
                            bundle2.putString(HiAnalyticsConstant.BI_KEY_RESUST, stringExtra);
                            bundle2.putString("secrityPhoneOrsecrityEmail", intent.getStringExtra("secrityPhoneOrsecrityEmail"));
                            if (intent.hasExtra("accountName")) {
                                bundle2.putString("accountName", intent.getStringExtra("accountName"));
                            }
                        } else {
                            bundle2.putString(HiAnalyticsConstant.BI_KEY_RESUST, stringExtra);
                        }
                        this.b.onFinish(bundle2);
                    } else {
                        this.b.onError((ErrorStatus) intent.getParcelableExtra(HwAccountConstants.EXTRA_OPLOG_ERROR));
                    }
                } catch (RuntimeException e) {
                    e.b("BindSafePhoneBroadcastReceiver", "BroadcastReceiver components are not allowed to register to receive intents", true);
                }
            }
        }
    }
}
